import { createFileRoute } from '@tanstack/react-router'
import Admins from '@/features/admins'
import { adminKeys, admins } from '@/api/admins'
import { rolesTableTree, rolesSelectTree, roleKeys } from '@/api/roles'
import { User } from '@/features/admins/data/schema'
import { TreeItem, ListItem } from '@/components/tree-select/schema'
export const Route = createFileRoute('/_authenticated/admins/')({
  component: Admins,
  loader: async ({ context: { queryClient } }): Promise<{ userList: User[]; rolesTree: TreeItem[]; rolesSelect: ListItem[] }> => {
    const res = await queryClient.fetchQuery({
      queryKey: adminKeys.all(),
      queryFn: admins,
    })
    const rolesTreeRes = await queryClient.fetchQuery({
      queryKey: roleKeys.rolesTableTree(),
      queryFn: rolesTableTree
    })
    const rolesSelectRes = await queryClient.fetchQuery({
      queryKey: roleKeys.rolesSelectTree(),
      queryFn: rolesSelectTree
    })
    return { userList: res.data.data, rolesTree: rolesTreeRes.data.data, rolesSelect: rolesSelectRes.data.data }
    // return [res.data, rolesTreeRes.data, rolesSelectRes.data];
  }
})
